//
//  HNSH_ExchangeHuaFeiItem.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/4/4.
//

#import "HNSH_ExchangeHuaFeiItem.h"

@interface HNSH_ExchangeHuaFeiItem ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

@end

@implementation HNSH_ExchangeHuaFeiItem

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setModel:(HNSH_ExchangeHuaFeiItemModel *)model {
    _model = model;
    self.moneyLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.platform_price doubleValue]];
    self.desLabel.text = [NSString stringWithFormat:@"送%.2f积分",[model.reward_amount doubleValue]];
    self.titleLabel.text = model.name;
}

- (void)setYkModel:(HNSH_ExchangeYouFeiItemModel *)ykModel {
    _ykModel = ykModel;
    self.moneyLabel.text = [NSString stringWithFormat:@"¥%.2f",[ykModel.price doubleValue]];
    self.desLabel.text = [NSString stringWithFormat:@"送%.2f积分",[ykModel.reward_amount doubleValue]];
    self.titleLabel.text = [NSString stringWithFormat:@"%@\n%@",ykModel.times,ykModel.title];
}

- (void)setSelect:(BOOL)select {
    _select = select;
    if (select) {
        self.titleLabel.textColor = self.moneyLabel.textColor = [UIColor appGreenColor];
        
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#ECF9F9"];
        self.bgView.layer.borderColor = [[UIColor appGreenColor] CGColor];
    } else {
        self.titleLabel.textColor = self.moneyLabel.textColor = [UIColor appGrayLabelColor];
        
        self.bgView.backgroundColor = [UIColor appBGColor];
        self.bgView.layer.borderColor = [[UIColor appBGColor] CGColor];
    }
}

- (void)addAllViews {
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.moneyLabel];
    [self addSubview:self.desLabel];
    
    self.userInteractionEnabled = YES;
    __weak __typeof(&*self)weakSelf = self;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
        if (weakSelf.clickBlock && weakSelf.model) {
            weakSelf.clickBlock(weakSelf.model);
        }
        if (weakSelf.ykClickBlock && weakSelf.ykModel) {
            weakSelf.ykClickBlock(weakSelf.ykModel);
        }
        weakSelf.select = YES;
    }];
    [self addGestureRecognizer:tap];
}

- (void)addAllLayout {
    
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(8, 0, self.width-16, 72)];
        _bgView.backgroundColor = [UIColor colorWithHexString:@"#ECF9F9"];
        _bgView.layer.cornerRadius = 4;
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.borderColor = [[UIColor appBGColor] CGColor];
        _bgView.layer.borderWidth = 1.0f;
    }
    return _bgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, self.width-16, 30)];
        _titleLabel.text = @"";
        _titleLabel.textColor = [UIColor appBGColor];
        _titleLabel.numberOfLines = 2;
        _titleLabel.font = [UIFont systemFontOfSize:12];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, self.width-16, 47)];
        _moneyLabel.text = @"¥30";
        _moneyLabel.textColor = [UIColor appBGColor];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:24];
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _moneyLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.height-18, self.width, 18)];
        _desLabel.text = @"";
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.font = [UIFont systemFontOfSize:13];
        _desLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _desLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
